package com.zifan.sever.service.impl;

import com.zifan.sever.bean.Role;
import com.zifan.sever.mapper.RoleMapper;
import com.zifan.sever.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zifan
 * @since 2021-04-10
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    /**
     * 判断roleName是否符合spring security标准
     * @param role
     * @return
     */
    @Override
    public boolean saveWithRoleName(Role role) {
        String roleName = role.getName();
        if (!roleName.startsWith("ROLE_")){
            roleName = "ROLE_" + roleName;
            role.setName(roleName);
        }
        return this.save(role);
    }

}
